package com.kt.mes.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.kt.mes.domain.Tray;
import com.kt.mes.service.ITrayService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 托盘功能Controller
 * 
 * @author lzc
 * @date 2021-04-29
 */
@RestController
@RequestMapping("/mes/tray")
public class TrayController extends BaseController
{
    @Autowired
    private ITrayService trayService;

    /**
     * 查询托盘功能列表
     */
    @PreAuthorize("@ss.hasPermi('mes:tray:list')")
    @GetMapping("/list")
    public TableDataInfo list(Tray tray)
    {
        startPage();
        List<Tray> list = trayService.selectTrayList(tray);
        return getDataTable(list);
    }

    /**
     * 导出托盘功能列表
     */
    @PreAuthorize("@ss.hasPermi('mes:tray:export')")
    @Log(title = "托盘功能", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Tray tray)
    {
        List<Tray> list = trayService.selectTrayList(tray);
        ExcelUtil<Tray> util = new ExcelUtil<Tray>(Tray.class);
        return util.exportExcel(list, "tray");
    }

    /**
     * 获取托盘功能详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:tray:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(trayService.selectTrayById(id));
    }

    /**
     * 新增托盘功能
     */
    @PreAuthorize("@ss.hasPermi('mes:tray:add')")
    @Log(title = "托盘功能", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Tray tray)
    {
        return toAjax(trayService.insertTray(tray));
    }

    /**
     * 修改托盘功能
     */
    @PreAuthorize("@ss.hasPermi('mes:tray:edit')")
    @Log(title = "托盘功能", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Tray tray)
    {
        return toAjax(trayService.updateTray(tray));
    }

    /**
     * 删除托盘功能
     */
    @PreAuthorize("@ss.hasPermi('mes:tray:remove')")
    @Log(title = "托盘功能", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(trayService.deleteTrayByIds(ids));
    }
}
